package com.alks.function.data.dto.procurement;

import com.alks.function.data.request.procurement.InstructionPackageMaterialDetailsRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

@Getter
@Setter
@NoArgsConstructor
@ToString
public class InstructionPackageDetailsDto {

    @ApiModelProperty(value = "ID", name = "id")
    private Integer id;

    @ApiModelProperty(value = "指令", name = "lotNo")
    private String lotNo;

    @ApiModelProperty(value = "形体", name = "style")
    private String style;

    @ApiModelProperty(value = "公司ID", name = "companyId")
    private String companyId;

    @ApiModelProperty(value = "序号")
    private BigDecimal seqNo;

    @ApiModelProperty(value = "包材类别")
    private String typeName;

    @ApiModelProperty(value = "物料编号")
    private String mtlNo;

    @ApiModelProperty(value = "物料名称")
    private String mtlName;

    @ApiModelProperty(value = "物料颜色")
    private String mtlColor;

    @ApiModelProperty(value = "物料规格")
    private String mtlSpec;

    @ApiModelProperty(value = "物料单位")
    private String mtlUnit;

    @ApiModelProperty(value = "需求量")
    private BigDecimal ttlUsage;

    @ApiModelProperty(value = "号码起")
    private String size1;

    @ApiModelProperty(value = "号码止")
    private String size2;

//    @ApiModelProperty(value = "创建时间")
//    private Date sysDate;

//    @ApiModelProperty(value = "创建人")
//    private String sysUser;

    @ApiModelProperty(value = "已入库量", name = "qty")
    private BigDecimal qty;

    @ApiModelProperty(value = "已入库颜色标志", name = "storagedFlag")
    private String storagedFlag;

    @ApiModelProperty(value = "已采购颜色标志", name = "purchasedFlag")
    private String purchasedFlag;

    @ApiModelProperty(value = "订购号")
    private String purNo;

    public boolean isEqualTo(InstructionPackageMaterialDetailsRequest other) {
        return Objects.equals(normalize(mtlNo), normalize(other.getMtlNo())) &&
                Objects.equals(normalize(mtlColor), normalize(other.getMtlColor())) &&
                Objects.equals(normalize(mtlName), normalize(other.getMtlName())) &&
                Objects.equals(normalize(mtlSpec), normalize(other.getMtlSpec())) &&
                Objects.equals(normalize(mtlUnit), normalize(other.getMtlUnit())) &&
                Objects.equals(normalize(size1), normalize(other.getSize1())) &&
                Objects.equals(normalize(size2), normalize(other.getSize2())) &&
                Objects.equals(seqNo, other.getSeqNo()) &&
                Objects.equals(typeName, other.getTypeName()) &&
                Objects.equals(ttlUsage, other.getTtlUsage());
    }

    private String normalize(String value) {
        if (value == null) {
            return null;
        }
        return value.trim().toLowerCase();
    }

    private BigDecimal normalize(BigDecimal value) {
        if (value == null) {
            return null;
        }
        return value.stripTrailingZeros();
    }
}
